import { BaseItemNormal } from "../../common/item/BaseItemNormal";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GNumericStepper } from "../../../../../com/mui/controls/GNumericStepper";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ShopItemInfo } from "../../../resource/info/ShopItemInfo";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ItemData } from "../../../resource/info/ItemData";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { EBind } from "../../../../../Message/Public/EBind";
import { Cache } from "../../../cache/Cache";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { _info } from "../../../../../this/_info";
import { _EBindNo } from "../../../../../EBind/_EBindNo";
type int = number;
//class RefreshMaterialItem
    
    export  class RefreshMaterialItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initUI();
            return;
        }

        /* internal  */initUI(): void
        {
            this.baseItem = new BaseItemNormal();
            this.baseItem.isDragAble = false;
            this.baseItem.isThrowAble = false;
            this.baseItem.isDropAble = false;
            this.baseItem.isShowLock = false;
            this.baseItem.setSize(32, 32);
            addChild(this.baseItem);
            this.nameLabel = ObjCreate.createLabel("PPP", 38, -5, 90, 20, flash.text.TextFormatAlign.LEFT, this, true, 16776960);
            this.addChild(this.nameLabel);
            this.buySp = new Object /* flash.display.Sprite */();
            this.addChild(this.buySp);
            this.pricetext = ObjCreate.createLabel(Language.getString(60330), 38, -5, 50, 20, flash.text.TextFormatAlign.LEFT, this.buySp, true, 11661311);
            this.pricetext.mouseEnabled = false;
            this.priceLabel = ObjCreate.createLabel("96", 70, -5, 50, 20, flash.text.TextFormatAlign.LEFT, this.buySp, true, 16770671);
            this.priceLabel.mouseEnabled = false;
            this.yb = GlobalClass.getBitmap(ImagesConst.Yuanbao);
            this.yb.x = 96;
            this.yb.y = -2;
            this.buySp.addChild(this.yb);
            this.numStepper = new GNumericStepper();
            this.numStepper.setSize(49, 22);
            this.numStepper.move(38, 12);
            this.numStepper.styleName = "NumericStepper";
            this.numStepper.drawNow();
            this.numStepper.textField.setStyle("upSkin", ResouceConst.getScaleBitmap("DisabledBg"));
            this.numStepper.textField.drawNow();
            this.numStepper.maximum = 99;
            this.numStepper.minimum = 1;
            this.buySp.addChild(this.numStepper);
            this.buyButton = ObjCreate.createGButton(Language.getString(60331), 94, 15, 38, 22, this.buySp);
            this.buyButton.addEventListener(flash.events.MouseEvent.CLICK, this.onBuyButtonClick);
            return;
        }

        /* internal  */onBuyButtonClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (typeof this._info === "shopiteminfo") 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallBuyItem, {"shopItemInfo": _info, "amount": this.numStepper.value}));
            }
            return;
        }

        public updateData(arg1): void
        {
            this._info = arg1;
            if (typeof this._info === "shopiteminfo") 
            {
                this._itemData = new ItemData(arg1.itemInfo.item.code);
                this.baseItem.itemData = this._itemData;
                this.priceLabel.htmlText = "" + this._info.tshopSell.price;
                this.buySp.visible = true;
                this.nameLabel.visible = false;
            }
            else if (typeof this._info === "itemdata") 
            {
                this._itemData = this._info;
                this.baseItem.itemData = this._itemData;
                this.nameLabel.htmlText = ItemsUtil.getItemName(this._info);
                this.buySp.visible = false;
                this.nameLabel.visible = true;
            }
            return;
        }

        public updateAmount(arg1: Boolean): void
        {
            var loc1=0;
            var loc2=0;
            if (this._itemData) 
            {
                loc1 = arg1 ? -1 : _EBindNo;
                loc2 = Cache.instance.pack.backPackCache.getItemCountByCategoryAndType(this._itemData.category, this._itemData.itemInfo.item.type, -1, this._itemData.itemInfo.item.color, loc1);
                this.baseItem.amount = loc2;
            }
            else 
            {
                this.baseItem.amount = 0;
            }
            if (this.baseItem.amount != 0) 
            {
                this.baseItem.filters = [];
            }
            else 
            {
                this.baseItem.filters = [FilterConst.colorFilter2];
            }
            return;
        }

        public set needAmount(arg1: int)
        {
            var loc1=0;
            if (this._itemData) 
            {
                loc1 = Cache.instance.pack.backPackCache.getItemCountByCategoryAndType(this._itemData.category, this._itemData.itemInfo.item.type, -1, this._itemData.itemInfo.item.color);
                this.baseItem.amount = arg1;
            }
            else 
            {
                this.baseItem.amount = 0;
            }
            if (loc1 < this.baseItem.amount) 
            {
                this.baseItem.filters = [FilterConst.colorFilter];
            }
            else 
            {
                this.baseItem.filters = [];
            }
            return;
        }

        protected /* var */baseItem: BaseItemNormal;

        protected /* var */nameLabel: GLabel;

        protected /* var */buySp: Object /* flash.display.Sprite */;

        protected /* var */pricetext: GLabel;

        protected /* var */priceLabel: GLabel;

        protected /* var */buyButton: GButton;

        protected /* var */_itemData: ItemData;

        protected /* var */_info;

        protected /* var */numStepper: GNumericStepper;

        protected /* var */yb: Object /* flash.display.Bitmap */;
    }
